home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / demo / text / eratos.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  1.6 KB  |  69 lines

  1. {
  2.     $Id: eratos.pp,v 1.2 2000/04/10 08:34:25 pierre Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1993-98 by Florian Klaempfl
  5.  
  6.     Eratos Example, Calculates all Prime Numbers from 1 to max
  7.  
  8.     See the file COPYING.FPC, included in this distribution,
  9.     for details about the copyright.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14.  
  15.  **********************************************************************}
  16. program eratosthenes;
  17.  
  18.   const
  19.      max = 1000000;
  20.   var
  21.      a : array[1..max] of boolean;
  22.  
  23.   procedure eratos;
  24.  
  25.     var
  26.        i,j : longint;
  27.  
  28.     begin
  29.        a[1]:=false;
  30.        for i:=2 to max do
  31.          a[i]:=true;
  32.        for i:=2 to max div 2 do
  33.          if a[i] then
  34.            for j:=2 to max div i do
  35.              a[i*j]:=false;
  36.        writeln;
  37.        j:=0;
  38.        for i:=1 to max do
  39.         begin
  40.           if a[i] then
  41.            begin
  42.              write(i:7);
  43.              inc(j);
  44.              if (j mod 10)=0 then
  45.               writeln;
  46.            end;
  47.         end;
  48.        writeln;
  49.     end;
  50.  
  51.   begin
  52.      write('Calculating the Prime Numbers from 1 to ',max,'...');
  53.      eratos;
  54.   end.
  55.  
  56. {
  57.   $Log: eratos.pp,v $
  58.   Revision 1.2  2000/04/10 08:34:25  pierre
  59.    1 is NOT a prime
  60.  
  61.   Revision 1.1  2000/03/09 02:49:09  alex
  62.   moved files
  63.  
  64.   Revision 1.5  1998/09/11 10:55:21  peter
  65.     + header+log
  66.  
  67.   Revision 1.4  1998/09/04 17:38:15  pierre
  68.     * the algorythm was wrong (unnecessary checks were made)
  69. }